<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax链式调用</title>
</head>
<body>
    
</body>
<script>
    function ajax(url){
        return new Promise((resolve,reject)=>{  //返回一个promise对象
            let xhr = new XMLHttpRequest();
            xhr.open('get',url);  //链接
            xhr.send()  //发送资源
            xhr.onreadystatechange = function(){   //监听状态
                console.log(xhr);
                if(xhr.readyState == 4){
                    if(xhr.status >= 200 && xhr.status < 300){
                        let res = JSON.parse(xhr.responseText)   //JSON字符串
                        resolve(res)
                    }else{
                        reject(xhr.responseText)
                    }
                }
            }
        })
    }
    ajax('./01.json')
    .then((res)=>{
        console.log(res);
        return ajax('./02.json')
    })
    .then((res)=>{
        console.log(res);
    })
    .catch((err)=>{
        console.log(err);
    })
    //ajax.then() =>??
    //ajsx.then() .catch()
</script>
</html>